<?php
namespace Home\Controller;

use Util\AccessController;

class CostController extends AccessController {

    /*
     * 获取用户余额
     */
    public function GetUserMoney() {
        $LS = Service('M', 'cost');
        $user_id = passport_decrypt($_POST['token'], C('JM_KEY'));
        $DATA = $LS->find(array('USER_ID' => $user_id));
        $data['money'] = passport_decrypt($DATA['MONEY'], C('JM_KEY'));
        $DATA = ResData($data);
        $this->ajaxReturn($DATA, 'JSON');
    }

    /*
     * 获取用户余额明细
     */
    public function GetUserCostLog() {
        $LS = Service('M', 'cost_log');
        $user_id = passport_decrypt($_POST['token'], C('JM_KEY'));
        $where['USER_ID'] = $user_id;
        $where['PAY_TYPE'] = 3;
        $order = 'CREATE_TIME desc';
        $data = $LS->query($where,null,null,$order);
        $DATA = ResData($data);
        $this->ajaxReturn($DATA, 'JSON');
    }

    /*
     * 资金加密
     * 字符串 金额
     */
    public function cost_encrypt(){
        $cost = (String)$_POST['cost'];
        $res = passport_encrypt($cost,C('JM_KEY'));
        $DATA = ResData($res);
        $this->ajaxReturn($DATA, 'JSON');
    }
    /*
     * 资金解密
     *
     */
    public function cost_decrypt(){
        $cost = (String)$_POST['cost'];
        $res = passport_decrypt($cost,C('JM_KEY'));
        $DATA = ResData($res);
        $this->ajaxReturn($DATA, 'JSON');
    }


}